package com.easy.util;

import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.ShearCaptcha;
import com.easy.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class CaptchaUtil {


//    private static LineCaptcha captcha = cn.hutool.captcha.CaptchaUtil.createLineCaptcha(200, 100);

    private  ShearCaptcha captcha = cn.hutool.captcha.CaptchaUtil.createShearCaptcha(200, 100, 5, 4);
    @Autowired
    RedisService redisService;
    public  String[] getImage(){
        captcha.createCode();
        String code=captcha.getCode();
        String key= UUID.randomUUID().toString();
        //将验证码存储起来
        redisService.setex(key,5*60,code);
        String imgBase=captcha.getImageBase64();
        String[] result={key,imgBase};

        return result;
    }


}
